﻿
using System;
using System.Collections.Generic;
namespace sharpxbot.Core.Security.Traffic.Counters
{
    /// <summary>
    /// Represents month counters. Always contains 31 day counters
    /// </summary>
    public class MonthCounters : BaseCounters
    {
        /// <summary>
        /// Gets month value
        /// </summary>
        public int Month { get; private set; }

        /// <summary>
        /// Gets array of day counters
        /// </summary>
        public DayCounters[] Days { get; private set; }

        /// <summary>
        /// Creates new month counters using given month and day counters array
        /// </summary>
        /// <param name="month">Must be from 0 to 11. (all bounds inclusive)</param>
        /// <param name="days">Array of day counters. Must be valid array of 31 items</param>
        public MonthCounters(int month, DayCounters[] days)
            :base()
        {
            Validator.ValidateMonth(month);

            if (days == null)
                throw new NullReferenceException("Illegal day counters array. Null-reference");

            if (days.Length < Constants.DaysCount)
                throw new ArgumentException(String.Format("Illegal day counters array. Must be {0} length", Constants.DaysCount));

            this.Month = month;
            this.Days = days;
        }

        /// <summary>
        /// Creates new month counters using given month and initializes day counters array
        /// </summary>
        /// <param name="month">Must be from 0 to 11. (all bounds inclusive)</param>
        public MonthCounters(int month)
            :base()
        {
            Validator.ValidateMonth(month);

            this.Month = month;

            InitDays();
        }

        /// <summary>
        /// Creates new month counters using current system time and initializes counters array
        /// </summary>
        public MonthCounters()
            :base()
        {
            this.Month = DateTime.Now.Month;

            InitDays();
        }

        #region Private methods

        private void InitDays()
        {
            List<DayCounters> days = new List<DayCounters>();

            for (int i = 0; i < Constants.DaysCount; ++i)
            {
                days.Add(new DayCounters(i));
            }

            this.Days = days.ToArray();
        }

        #endregion
    }
}
